﻿<%@ WebHandler Language="C#" Class="mesFeedBackTaskList" %>

using System;
using System.Web;
using BusinessRule.DTO;
using System.Data;
using DatabaseAccess.DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;

public class mesFeedBackTaskList : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {

        string sql = @"
SELECT e.employeeid,e.fullname,e.password,e.employeename,t.userid,
       t.id taskid,t.processinstid,t.tasktitle,t.begintime,
       --t.prevtasktitle,t.prevuser,
       e2.employeename employeename2,e2.fullname fullname2,
       DECODE(t.taskstate,1,'常规待办任务',2,'只读传阅任务',3,'待办任务',4,'只读传阅任务',9,'系统通知任务',11,'加签任务') tasktype,
       'http://10.15.7.194:8088/portal/r/or?cmd=CLIENT_BPM_FORM_MAIN_PAGE_OPEN&openState=1&displayToolbar=true&oauthName=wps&user=' || t.userid || '&processInstId=' || t.processinstid || '&taskInstId=' || t.id taskurl
FROM employee e 
INNER JOIN awsprd.feedback_wfctask@bpm195 t ON t.userid = 'MES_' || e.employeename
LEFT JOIN employee e2 ON 'MES_' || e2.employeename = t.prevuser
WHERE 1=1 ";
        if (context.Request.Form["employeeid"] != null)
        {
            sql += string.Format(" AND e.employeeid='{0}'", context.Request.Form["employeeid"].ToString());
        }
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);

        foreach (DataColumn col in dt.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }

        var json = JsonConvert.SerializeObject(dt);
        context.Response.ContentType = "text/json";

        json = "{\"data\":" + json.ToString()
                + ",\"count\":" + dt.Rows.Count
                + ",\"code\":" + "0"
                + ",\"msg\":" + "0"
                + "}";

        context.Response.Write(json);
        context.Response.End();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}